﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using MingleReport.HttpRequests;
using MingleReport.Services;

namespace MingleReport
{
    public partial class MingleReportingForm : Form
    {
        private readonly IMingleSession application;
        private readonly IStoryCardRepository storyCardRepository;

        public MingleReportingForm(IMingleSession application)
        {
            this.application = application;
            this.Name = "MingleReportingForm";
            InitializeComponent();
            storyCardRepository = new StoryCardRepository(application, new HttpRequestFactory(), new XmlDocumentParser<StoryCard>());
            initSearch();
        }

        private void initSearch()
        {
            List<string> cardTypesDisplayList = storyCardRepository.GetAllCardTypesByProjectId();
            TypeListComboBox.DataSource = cardTypesDisplayList;   
        }

        private void exportAllProperties()
        {
            List<StoryCard> cards = storyCardRepository.GetAllStoryCardsByProjectId();
            new MingleExcel(application).Export(cards);
            Close();
        }

        private void searchButton_Click(object sender, EventArgs e)
        {
            /** TODO this should actually render in same window, not pop up in new window. The new window that shows up is just a mockup of what should show up */
            string type = TypeListComboBox.SelectedItem.ToString();
            new SearchPropertiesForm(application, type).Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            exportAllProperties();
        }
    }
}